package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: CategoryController
 *
 * @AUTHOR: zhang
 * DATE: 2023/11/22
 * DESCRIPTION :
 */
@Slf4j
@Api(tags = "B端-分类信息表现层接口") //@Api:用户描述类的相关信息
@RestController("adminCategoryController")
@RequestMapping("/admin/category") //声明访问路径为/admin/employee自动映射到此方法
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @ApiOperation("分类列表查询")
    @GetMapping("/page")
    public Result<PageResult> getPage(CategoryPageQueryDTO dto){
        log.info("【分类列表查询】");
        PageResult pageResult = categoryService.getPage(dto);
        return Result.success(pageResult);
    }

    @ApiOperation("新增分类信息")
    @PostMapping
    public Result insertCategory(@RequestBody CategoryDTO dto){
        log.info("【新增分类信息】");
        categoryService.insert(dto);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改分类信息")
    public Result updateCategory(@RequestBody CategoryDTO dto){
        log.info("【修改分类信息】");
        categoryService.update(null,dto);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("修改分类信息状态")
    public Result updateStatus(@PathVariable Integer status,CategoryDTO dto){
        log.info("【修改分类信息状态】");
        categoryService.update(status,dto);
        return Result.success();
    }

    @ApiOperation("根据id删除分类信息状态")
    @DeleteMapping
    public Result deleteCategory(Long id){
        log.info("【根据id删除分类信息状态】");
        categoryService.delete(id);
        return Result.success();
    }

    /**
     * 根据分类类型查询分类信息
     */
    @ApiOperation("根据分类类型查询分类信息")
    @GetMapping("/list")
    public Result selectCategoryByType(Integer type){
        List<Category> categoryList = categoryService.selectCategoryByType(type);
        return Result.success(categoryList);
    }
}
